package org.exercise7.cmd;

import org.exercise7.cmd.order.Order;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/11/28 20:21
 */
public class QuadricCalculator implements Calculator {

    List<Order> orderList = new ArrayList<>();

    private int start;

    private int num;

    public QuadricCalculator(int start) {
        this.start = start;
        this.num = start;
    }

    @Override
    public int calculate() {
        for (Order order : orderList) {
            num = order.invoke(num);
        }
        return num;
    }

    /**
     * 撤销上一步
     */
    @Override
    public void revoke() {
        orderList.remove(orderList.size() - 1);
    }

    /**
     * 重做操作
     */
    @Override
    public void redo() {
        orderList.clear();
        this.num = this.start;
    }


    public void setOrder(Order order) {
        this.orderList.add(order);
    }
}
